package com.neno.controller;

import com.neno.model.User;
import com.neno.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class HelloController {
    private Logger log = LoggerFactory.getLogger(HelloController.class);
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/getuserlists", method = RequestMethod.GET)
    public List<User> getUserLists() {
        return userService.selectUsers();
    }

    @RequestMapping(value = "/{email}/getuser01", method = RequestMethod.GET)
    /**
     * @RequestMapping(value = "/getuser01/{email}", method = RequestMethod.GET)
     * 这种情况在我的电脑上的postman上输入email值为123@163.com,但是获取到的email值为123@163
     */
    public User getUser01(@PathVariable("email") String email) {
        log.info("getUser01 email : " + email + "++++++++++");
        return userService.getUser(email);
    }

    @RequestMapping(value = "/{name}/{password}/getuser02", method = RequestMethod.GET)
    public User getUser02(@PathVariable("name") String name, @PathVariable("password") String password) {
        log.info("getUser02 name : " + name + " ++++++++++ password : " + password);
        return userService.getUser(name, password);
    }

    @RequestMapping(value = "/insertuser", method = RequestMethod.POST)
    public int insertUser(User user) {
        log.info("insertUser : " + user.toString());
        int i = userService.insertUser(user);
        return i;
    }

    @RequestMapping(value = "/deleteuser", method = RequestMethod.POST)
    public int deleteUser(String email) {
        log.info("deleteUser : " + email);
        int i = userService.deleteUser(email);
        return i;
    }

    @RequestMapping(value = "/updateuser", method = RequestMethod.POST)
    public int updateUser(User user) {
        log.info("updateUser : " + user.toString());
        int i = userService.updateUser(user);
        return i;
    }
}
